package com.openbravo.pos.printer.config;

import java.awt.Component;

import javax.swing.GroupLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;

import com.openbravo.data.user.DirtyManager;
import com.openbravo.pos.config.ParametersConfig;
import com.openbravo.pos.util.StringParser;

public class ParametersLan extends JPanel implements ParametersConfig{

	private JTextField m_jtxtJAddr;
	private JTextField m_jtxtJPoint;

	/**
	 * Create the panel.
	 */
	public ParametersLan() {
		
		JPanel panel = new JPanel();
		add(panel);
		
		JLabel label = new JLabel();
		label.setText("打印机IP地址");
		
		m_jtxtJAddr = new JTextField();
		
		JLabel label_1 = new JLabel();
		label_1.setText("端口号(9100)");
		
		m_jtxtJPoint = new JTextField();
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGap(0, 432, Short.MAX_VALUE)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addComponent(label, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(m_jtxtJAddr, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(m_jtxtJPoint, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(30, Short.MAX_VALUE))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGap(0, 24, Short.MAX_VALUE)
				.addGroup(gl_panel.createSequentialGroup()
					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
						.addComponent(m_jtxtJAddr, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(label_1)
						.addComponent(m_jtxtJPoint, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(label))
					.addGap(184))
		);
		panel.setLayout(gl_panel);

	}

	@Override
	public Component getComponent() {
		return this;
	}

	@Override
	public void addDirtyManager(DirtyManager dirty) {
		m_jtxtJPoint.addActionListener(dirty);
		m_jtxtJAddr.addActionListener(dirty);
	}

	@Override
	public void setParameters(StringParser p) {
		m_jtxtJAddr.setText(p.nextToken(','));
		m_jtxtJPoint.setText(p.nextToken(','));
	}

	@Override
	public String getParameters() {
		return m_jtxtJAddr.getText() + "," + m_jtxtJPoint.getText();
	}

}
